<?
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
require ("s_inc.php");
$rows = 20;
$page	  = $_REQUEST['page']?$_REQUEST['page']:1;
//權限
admin_main::pageChk('cats_set');
?>
<?php require("s_head.tpl.php"); ?>
<?
$db_goods = &new db($scfg['db']['goods']);
$c1id     =  $_GET['c1id'];
$c2id     =  $_GET['c2id'];
$c3id     =  $_GET['c3id'];
$c1		  =  $db_goods->rsArray("select * from `cats_c1` where c1id= ? ",$c1id);
$c2		  =  $db_goods->rsArray("select * from `cats_c2` where c2id= ? ",$c2id);
$c3		  =  $db_goods->rsArray("select * from `cats_c3` where c3id= ? ",$c3id);
$table 	  = 'cats_c4';
if($_POST)
{
	$act = $_POST['act'];
	if($act == 'modify')
	{
		//print_r($_POST);
		//更新
		$c4id = $_POST['c4id'];
		$c3id = $_POST['c3id'];
		$c2id = $_POST['c2id'];
		$c1id = $_POST['c1id'];
		$name = $_POST['name'];
		$taxis = $_POST['taxis'];
		if(is_array($c4id))
		{
			foreach($c4id as $k=>$v)
			{
				$bind = array(
					'name'=>$name[$k],
					'taxis'=>$taxis[$k],
					'c1id'=>$c1id[$k],
					'c2id'=>$c2id[$k],
					'c3id'=>$c3id[$k],
				);
				$db_goods->update($table,$bind," c4id = ? ",$v);
			}
			$db_goods->update("cats_c3",array("sub"=>"1")," c3id in (?) ",$c3id);
		}
		//刪除
		$del = $_POST['del'];
		if(is_array($del))
		{
			$db_goods->delete("cats_c4"," c4id in (?) ",$del);
		}
	}elseif($act == 'add')
	{
		if($_POST['name'])
		{
			$bind = array(
			    'c3id'=>$_POST['c3id'],
			    'c2id'=>$_POST['c2id'],
				'c1id'=>$_POST['c1id'],
				'name'=>$_POST['name'],
				'taxis'=>$_POST['taxis'],
				'tbid'=>$_POST['tbid'],
			);
			$id = $db_goods->insert($table,$bind);
			if($id)
			{
				$db_goods->update("cats_c3",array("sub"=>"1")," c3id = ? ",$_POST['c3id']);
				echo g::msg("添加成功! ");
			}else
			{
				echo g::msg("失败,请重试! ");
			}
		}
	}
}
$rs = $db_goods->dataArray("select * from {$table} where c3id = ? order by taxis",$c3['c3id']);
//print_r($p);
?>
<form method="post">
<table width="100%"  border="0" cellpadding="4" cellspacing="1" class="tableoutline">
	<tr>
	<td colspan="5" class="tbhead">分類 -- <?=$c1['name']?> -- <?=$c2['name']?> -- <?=$c3['name']?></td>
  </tr>
  <tr class="_data_" style="font-weight:bold;">
	<td width="5%" align="right" style="color:#FF0000;">刪?</td>
	<td width="48%" align="left">分類名稱</td>
    <td width="17%" align="left">排序</td>
    <td width="12%" align="left">tbid</td>
    <td width="18%" align="left">是否有下级</td>
  </tr>
 <?
  	if(is_array($rs))
	{
		foreach($rs as &$v)
		{
			?>
			<tr class="_data_">
			<input name="c1id[<?=$v['c4id']?>]" type="hidden" value="<?=$v['c1id']?>" />
			<input name="c2id[<?=$v['c4id']?>]" type="hidden" value="<?=$v['c2id']?>" />
			<input name="c3id[<?=$v['c4id']?>]" type="hidden" value="<?=$v['c3id']?>" />
			<input name="c4id[<?=$v['c4id']?>]" type="hidden" value="<?=$v['c4id']?>" />
			<td width="5%" align="right"><input type="checkbox" name="del[]" value="<?=$v['c4id']?>" /></td>
			<td align="left"><input name="name[<?=$v['c4id']?>]" type="text" value="<?=$v['name']?>" size="32" maxlength="32" />
			><a href="#_cats_ext.php?c1id=<?=$v['c1id']?>&c2id=<?=$v['c2id']?>&c3id=<?=$v['c3id']?>&c4id=<?=$v['c4id']?>">添加属性</a>
			><a href="#_cats_pct.php?c1id=<?=$v['c1id']?>&c2id=<?=$v['c2id']?>&c3id=<?=$v['c3id']?>&c4id=<?=$v['c4id']?>">添加同属性商品</a>
			</td>
			<td align="left"><input name="taxis[<?=$v['c4id']?>]" type="text" value="<?=$v['taxis']?>" size="2" maxlength="2" /></td>
			<td align="left"><?=$v['tbid']?></td>
			<td align="left"><?=$v['sub']?></td>
			</tr>
			<?
		}
	}

  ?>
 <tr class="_data_">
	<td>&nbsp;</td>
	<td colspan="4"><input name="Submit" type="submit" class="bginput" value="  送 出 ">
	<input name="Submit" type="reset" class="bginput" value=" 重 設 ">
	<input name="act" type="hidden" id="act" value="modify"></td>
  </tr>
</table>
</form>
  
 <hr />
<form name="addcats" method="post" onsubmit="return XypForm(this)">
<table width="100%" border="0" cellpadding="4" cellspacing="1" class="tableoutline">
        <tr>
        <td colspan="2" class="tbhead">在《<?=$c1['name']?>》=>《<?=$c2['name']?>》=>《<?=$c3['name']?>》分類下添加新的分类</td>
      </tr>
	  <tr class="_data_">
        <td width="14%" align="right">所属主分类：        </td>
        <td width="86%" align="left"><input name="c1id" type="hidden" value="<?=$c1['c1id']?>" />
		<a href="_cats.php"><?=$c1['name']?></a></td>
      </tr>
	  <tr class="_data_">
        <td width="14%" align="right">所属二级次分类：        </td>
        <td width="86%" align="left"><input name="c2id" type="hidden" value="<?=$c2['c2id']?>" />
		<a href="_cats2.php?c1id=<?=$c1['c1id']?>"><?=$c2['name']?></a></td>
      </tr>
	  <tr class="_data_">
        <td width="14%" align="right">所属三级次分类：        </td>
        <td width="86%" align="left"><input name="c3id" type="hidden" value="<?=$c3['c3id']?>" />
		<a href="_cats3.php?c1id=<?=$c1['c1id']?>&c2id=<?=$c2['c2id']?>"><?=$c3['name']?></a></td>
      </tr>
	  <tr class="_data_">
		<td align="right">分類名稱：</td>
		<td align="left"> 
		 <input name="name" require="1"  type="text" id="name" size="20" maxlength="32">
		 (必选)</td>
	  </tr>
	  <tr class="_data_">
        <td width="14%" align="right">排序：        </td>
        <td width="86%" align="left"><input name="taxis" require="1" dataType="nums"  type="text" id="taxis" size="10" maxlength="10" value="0">
          (必选)</td>
      </tr>
	  
      <tr class="_data_">
        <td align="right" valign="top">tbid：</td>
        <td align="left"><input name="tbid" type="text" id="tbid" size="10" maxlength="10" />
          (可选)</td>
      </tr>
      <tr class="_data_">
        <td>&nbsp;</td>
        <td><input type="submit" class="bginput" value="送出">
        <input type="reset" class="bginput" value="重設">
        <input name="act" type="hidden" id="act" value="add"></td>
      </tr>
</table>
</form>

<? include("s_copyRight.tpl.php"); ?>